﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace AMix
{
    public partial class CatalogFrm : FrmRezumat
    {
        public CatalogFrm(ModuleClass mInfo)
            : base(mInfo)
        {
            InitializeComponent();
            workConnString = "ESRPConnectionString";
        }

        private void CatalogFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.amixCatalogTableAdapter.Connection = con;
            this.amixCatalogTableAdapter.Fill(this.eSRPDataSet.AmixCatalog);
            InchideConexiune(con);
            AddButton("Salveaza", global::ERPStudio.Properties.Resources.salvare, Salvare, ToolStripItemAlignment.Right, true);
            listBndSourceMain.Add(amixCatalogBindingSource);
            listTableAdaptor.Add(amixCatalogTableAdapter.Adapter);
            amixCatalogBindingSource.Sort = "Cod";
        }

        private void amixCatalogDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
                return;
            if (e.ColumnIndex == clasaColumn.Index || e.ColumnIndex == subclasaColumn.Index ||
                e.ColumnIndex == grupaColumn.Index || e.ColumnIndex == subgrupaColumn.Index ||
                e.ColumnIndex == familiaColumn.Index)
            {
                String newVal = amixCatalogDGV[grupaColumn.Index, e.RowIndex].Value.ToString();
                if (amixCatalogDGV[subgrupaColumn.Index, e.RowIndex].Value.ToString() != String.Empty &&
                    amixCatalogDGV[subgrupaColumn.Index, e.RowIndex].Value.ToString() != "0")
                {
                    newVal += "." + amixCatalogDGV[subgrupaColumn.Index, e.RowIndex].Value.ToString();
                    if (amixCatalogDGV[clasaColumn.Index, e.RowIndex].Value.ToString() != String.Empty &&
                        amixCatalogDGV[clasaColumn.Index, e.RowIndex].Value.ToString() !="0")
                    {
                        newVal += "." + amixCatalogDGV[clasaColumn.Index, e.RowIndex].Value.ToString();
                        if (amixCatalogDGV[subclasaColumn.Index, e.RowIndex].Value.ToString() != String.Empty &&
                            amixCatalogDGV[subclasaColumn.Index, e.RowIndex].Value.ToString() != "0")
                        {
                            newVal += "." + amixCatalogDGV[subclasaColumn.Index, e.RowIndex].Value.ToString();
                            if (amixCatalogDGV[familiaColumn.Index, e.RowIndex].Value.ToString() != String.Empty &&
                                amixCatalogDGV[familiaColumn.Index, e.RowIndex].Value.ToString() != "0")
                                newVal += "." + amixCatalogDGV[familiaColumn.Index, e.RowIndex].Value.ToString();

                        }

                    }
                   
                }
                if (amixCatalogDGV[codColumn.Index, e.RowIndex].Value.ToString() != newVal)
                    amixCatalogDGV[codColumn.Index, e.RowIndex].Value = newVal;
               
 
            }
        }
    }
}
